package com.ruoyi.ai.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ai.domain.vo.WxNumChangeVo;
import com.ruoyi.ai.domain.bo.WxNumChangeBo;
import com.ruoyi.ai.service.IWxNumChangeService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 次数变更流水
 *
 * @author yh
 * @date 2024-04-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/ai/numChange")
public class WxNumChangeController extends BaseController {

    private final IWxNumChangeService iWxNumChangeService;

    /**
     * 查询次数变更流水列表
     */
    @SaCheckPermission("ai:numChange:list")
    @GetMapping("/list")
    public TableDataInfo<WxNumChangeVo> list(WxNumChangeBo bo, PageQuery pageQuery) {
        return iWxNumChangeService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出次数变更流水列表
     */
    @SaCheckPermission("ai:numChange:export")
    @Log(title = "次数变更流水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(WxNumChangeBo bo, HttpServletResponse response) {
        List<WxNumChangeVo> list = iWxNumChangeService.queryList(bo);
        ExcelUtil.exportExcel(list, "次数变更流水", WxNumChangeVo.class, response);
    }

    /**
     * 获取次数变更流水详细信息
     *
     * @param changeId 主键
     */
    @SaCheckPermission("ai:numChange:query")
    @GetMapping("/{changeId}")
    public R<WxNumChangeVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long changeId) {
        return R.ok(iWxNumChangeService.queryById(changeId));
    }

    /**
     * 新增次数变更流水
     */
    @SaCheckPermission("ai:numChange:add")
    @Log(title = "次数变更流水", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody WxNumChangeBo bo) {
        return toAjax(iWxNumChangeService.insertByBo(bo));
    }

    /**
     * 修改次数变更流水
     */
    @SaCheckPermission("ai:numChange:edit")
    @Log(title = "次数变更流水", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody WxNumChangeBo bo) {
        return toAjax(iWxNumChangeService.updateByBo(bo));
    }

    /**
     * 删除次数变更流水
     *
     * @param changeIds 主键串
     */
    @SaCheckPermission("ai:numChange:remove")
    @Log(title = "次数变更流水", businessType = BusinessType.DELETE)
    @DeleteMapping("/{changeIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] changeIds) {
        return toAjax(iWxNumChangeService.deleteWithValidByIds(Arrays.asList(changeIds), true));
    }
}
